/**
 * code by zmdms-business 2023-08-29
 */

import { AxiosRequest, Crypto } from "zmdms-utils";
import { Modal, message } from "zmdms-webui";
import { API_URL } from "./baseUrl";

const request = new AxiosRequest({
  baseURL: API_URL,
  // 数据加密传输
  crypto: new Crypto("O2BEeIv399qHQNhD6aGW8R8DEj4bqHXm", "jMVCBsFGDQr1USHo"),
  // 是否显示超时的弹框
  isTimeoutConfirm: true,
  // 登录过期跳转到登录页的方法
  jumpCallback: (status: number) => {
    window.history.pushState(null, "", "/login");
    window.dispatchEvent(new PopStateEvent("popstate"));
  },
  // 消息弹出提示
  messageWarning: (msg: string, duration: number, callback?: () => void) => {
    message.warning(msg, duration, callback);
  },
  // 需要用户点击的弹出提示
  modalConfirm: (msg: string, callback?: () => void) => {
    Modal.confirm({
      width: 500,
      style: { whiteSpace: "pre-line" },
      title: msg,
      okCancel: false,
      onOk: callback,
    });
  },
});

export default request.request.bind(request);
